package com.base.study.presenter;

import android.app.Activity;
import android.text.TextUtils;
import android.util.Log;

import com.base.commonlib.base.presenter.BasePresenter;
import com.base.commonlib.http.RealNetWorkUtil;
import com.base.commonlib.http.utils.CallBackImpl;
import com.base.study.bean.OnlineStudyListBean;
import com.base.study.bean.ScopeBean;
import com.base.study.view.OnlineStudyListView;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import io.reactivex.disposables.Disposable;

/**
 * Created by Administrator on 2020/2/21.
 */

public class OnlineStudyListPresenter extends BasePresenter<OnlineStudyListView> {
    public OnlineStudyListPresenter(OnlineStudyListView view, Activity activity) {
        super(view, activity);
    }

    public void getList(final Integer page, Integer limit){
        Map<String, Integer> map = new HashMap<>();
        map.put("page",page);
        map.put("limit", limit);
        Disposable enqueue = RealNetWorkUtil.postContent().method("api-train/course/query").content(map)
                .build().enqueue(OnlineStudyListBean.class, new CallBackImpl<OnlineStudyListBean>() {
                    @Override
                    public void onError(int code, String msg, String errMsg) {
                        mView.showError();
                        mView.returnError();
                    }

                    @Override
                    public void onNext(OnlineStudyListBean list) {
//                        if (page==1){
//                            //刷新
//                            if (list!=null &&list.getRows() != null&&list.getRows().size()>0){
//                                mView.returnList(list);
//                                //mView.returnNoData();
//                            }else {
//                                mView.returnNoData();
//                            }
//                        }else {
//                            //更多
//                            if (list!=null &&list.getRows() != null&&list.getRows().size()>0){
//                                mView.returnMoreList(list);
//                            }else {
//                                mView.returnNoMoreData();
//                            }
//                        }
                    }
                });

        mCompositeDisposable.add(enqueue);
    }


    /**
     * 获取积分
     */
    public void getScope(String str){
        Map<String, String> map = new HashMap<>();
        map.put("funcMainId",str);
        Disposable enqueue = RealNetWorkUtil.postContent().method("api-function/integral/getInfo").content(map)
                .build().enqueue(ScopeBean.class, new CallBackImpl<ScopeBean>() {
                    @Override
                    public void onError(int code, String msg, String errMsg) {
                        mView.showError();
                        mView.returnError();
                    }

                    @Override
                    public void onNext(ScopeBean sc) {
                        mView.returnScope(sc);
                    }
                });

        mCompositeDisposable.add(enqueue);
    }
}
